<?php

class UserController extends CController {

    protected $user;
    protected $current_location;
    public function init() {
        parent::init();
        $this->user = Yii::app()->session['user'];
        if (empty($this->user)) {
            $this->redirect(array('account/login'));
        }
        $this->layout = 'layout2';
    }    

    protected function compareSaveJob($listId = array()) {
        $rs = array();
        if (!empty($listId) && !empty($this->user)) {
            $condition = new CDbCriteria();
            $condition->select = 'job_id';
            $condition->condition = 'uid = ' . $this->user['id'] . ' AND job_id IN (' . implode(',', $listId) . ')';
            $saveJob = SaveJob::model()->findAll($condition);
            if (!empty($saveJob)) {
                foreach ($saveJob as $item) {
                    $rs[] = $item->job_id;
                }
            }
        }
        return $rs;
    }

    protected function compareAddNote($listId = array()) {
        $rs = array();
        if (!empty($listId) && !empty($this->user)) {
            $condition = new CDbCriteria();
            $condition->select = 'job_id, note, tags';
            $condition->condition = 'uid = ' . $this->user['id'] . ' AND job_id IN (' . implode(',', $listId) . ')';
            $saveJob = Note::model()->findAll($condition);
            if (!empty($saveJob)) {
                foreach ($saveJob as $item) {
                    $rs[$item->job_id] = $item;
                }
            }
        }
        return $rs;
    }

}